import os
import sys
import argparse
import uvicorn

from llm_server.server.settings import Settings, ServerSettings, ModelSettings
from llm_server.server.cli import add_args_from_model, parse_model_from_args
from llm_server.server.app import create_app

def main():
    description = "Openai python server. Host your own LLMs!🚀"
    parser = argparse.ArgumentParser(description=description)

    add_args_from_model(parser, Settings)

    args = parser.parse_args()

    server_settings = parse_model_from_args(ServerSettings, args)
    model_settings = [parse_model_from_args(ModelSettings, args)]

    app = create_app(
        server_settings=server_settings,
        model_settings=model_settings,
    )
    uvicorn.run(
        app,
        host=os.getenv("HOST", server_settings.host),
        port=int(os.getenv("PORT", server_settings.port)),
        ssl_keyfile=server_settings.ssl_keyfile,
        ssl_certfile=server_settings.ssl_certfile,
    )

    
if __name__ == "__main__":
    main()